/*
 * OpenParts
 * A dynamic-loading components framework for GWT
 * Copyright (C) 2011 Christophe Bouthier  [chris{AT}binary-gastronome{DOT}fr]
 *
 * This work is partially based on work I have done at INRIA (http://www.inria.fr) 
 * in the context of the Qualipso European Project (http://qualipso.org/),
 * The work done at INRIA is Copyright (C) 2006-2011 INRIA
 *
 * This work is distributed under the LGPL version 3
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3
 * as published by the Free Software Foundation. See the GNU
 * Lesser General Public License in LGPL.txt for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package fr.openparts.OpenParts.client;


import com.google.gwt.core.client.JavaScriptObject;

/**
 * Binding part of the scheduler, registering necessary handler for scheduling ({@link OPCommand}).
 * 
 * @author Christophe Bouthier [chris{AT}binary-gastronome{DOT}fr]
 * @creation.date 09 November 2010
 */
public final class OPSchedulerBinding extends JavaScriptObject {
    
    /**
     * Returns a binding object to encapsulate an {@link OPScheduler}.
     * 
     * @return a binding object to encapsulate an OPScheduler. Cannot be null.
     */
    public static final native OPSchedulerBinding schedulerBindingFactory() /*-{
        var schedulerBinding = {};
        schedulerBinding.scheduleCommand = null;
        return schedulerBinding;
    }-*/;

    /**
     * Protected constructor, necessary because it's a JavaScriptObject.
     */
    protected OPSchedulerBinding() {
    }
    
    /**
     * Schedule the given {@link OPCommand} to be executed by {@link OPScheduler}. Don't do anything if the scheduler hasn't been binded.
     * 
     * @param command
     *            the command to schedule. Shouldn't be null.
     */
    public void scheduleCommand(final OPCommand command) {
        assert command != null : "parameter command shouldn't be null";

        scheduleCommandImpl(command);
    }

    /**
     * Real implementation of scheduling the command to be executed by the scheduler. Don't do anything if the scheduler hasn't been binded.
     * 
     * @param command
     *            the command to schedule.
     */
    private final native void scheduleCommandImpl(final OPCommand command) /*-{
        if (this.scheduleCommand != null) {
            this.scheduleCommand(command);
        }
    }-*/;

}
